﻿using System.Collections;
using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using Kratos.Framework.Extensions.RouteExtensions;
using Kratos.Framework.Infrastructures;
using Kratos.Modules.Order.Services;
using Kratos.Modules.Order.Services.Impl;
using Microsoft.Practices.Unity;

namespace Kratos.Modules.Order
{
    public class OrderModule : IKratosModule, IKratosDataProvider
    {
        private readonly IUnityContainer _container;

        public OrderModule(IUnityContainer container)
        {
            _container = container;
        }

        public void Initialize()
        {

        }

        public void RegisterRoutes(RouteCollection routes)
        {
            var space = new[] { "Kratos.Modules.Order.Controllers" };

            routes.MapLowerCaseRoute(
                "account",
                "account/{action}",
                new { controller = "account", action = "LogOn" },
                null,
                space
                );

            routes.MapLowerCaseRoute(
                "order",
                "order/{action}",
                new { controller = "Order", action = "Index" },
                null,
                space
                );

            routes.MapLowerCaseRoute(
                "product",
                "product/{action}/{id}",
                new { controller = "Product", action = "Create", id = UrlParameter.Optional },
                new { id = @"\d*" },
                space
                );
        }

        public void RegisterModelBinders(ModelBinderDictionary modelBinders)
        {

        }

        public void RegisterBizServices()
        {
            _container.RegisterType<IProductService, ProductService>();
            _container.RegisterType<IOrderService, OrderService>();
        }

        public void RegisterAction()
        {
            var assembly = Assembly.GetExecutingAssembly();
            SecurityHelper.SetActionByAssembly(assembly);
        }

        public void Unload()
        {

        }

        public void ConfigDataProvider()
        {

        }
    }
}
